<?php
session_start();
    
    // Created By : Julian Ponce
    // B.S. Computer Science - De La Salle Canlubang
    // December 4, 2011
    // IN PARAMETERS : 
    // 
    // This AJAX Requests gets all permission in the system.

    include('../includes/siteConfig.php');
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    
    // GET PREVIOUS STEP ID BY CHECKING LOGS
    $query = 
        "
            SELECT *
            FROM Permission
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
     
    
    if (mysql_num_rows($result) > 0) {
        // SAVE QUERY RESULTS TO AN ARRAY > $row. Each row will be placed to a list ($permissionList).  
        while ($row = mysql_fetch_array($result)) {
            $permissionData = array();
            $permissionData['permissionId'] = $row['permissionId'];
            $permissionData['permissionName'] = $row['permissionName'];

            $permissionList[] = $permissionData;
        }

        echo json_encode($permissionList);
    }
    
    else {
        echo json_encode(0);
    }
    
    mysql_free_result($result);
    mysql_close($connect);
?>
